package dnd;

import java.awt.Color;
import java.util.ArrayList;

import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.BorderFactory;

@SuppressWarnings("serial")
public class Character extends JPanel {
	private JTextField playerNameText, charNameText, charAgeText;
		
	public Character() {
		setBackground(Color.DARK_GRAY);
		setVisible(false);

		initBasicInfo();
		initRaces();
		
	}
	
	public void initBasicInfo() {
		//instantiate basic info variables
		JPanel basicInfoPanel = new JPanel();
		basicInfoPanel.setLayout(new BoxLayout(basicInfoPanel, BoxLayout.Y_AXIS));
		JLabel playerNameLabel = new JLabel("Player Name: ");
		playerNameText = new JTextField(20);
		JLabel charNameLabel = new JLabel("Character Name: ");
		charNameText = new JTextField(20);
		JLabel charAgeLabel = new JLabel("Character Age: ");
		charAgeText = new JTextField(20);
		
		basicInfoPanel.add(playerNameLabel);
		basicInfoPanel.add(playerNameText);
		basicInfoPanel.add(charNameLabel);
		basicInfoPanel.add(charNameText);
		basicInfoPanel.add(charAgeLabel);
		basicInfoPanel.add(charAgeText);
		
		basicInfoPanel.setBackground(Color.LIGHT_GRAY);
		basicInfoPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.GRAY), "Basic Character Info"));
		add(basicInfoPanel);
	}
	
	public void initRaces() {
		//instantiate race variables
		JPanel racePanel = new JPanel();
		ArrayList<JRadioButton> race = new ArrayList<JRadioButton>();
		ButtonGroup raceGroup = new ButtonGroup();
		
		
		//add races into the race array list
		race.add(new JRadioButton("Human"));
		race.add(new JRadioButton("Elf"));
		race.add(new JRadioButton("Dwarf"));
		race.add(new JRadioButton("Orc"));
		race.add(new JRadioButton("Halfling"));
		
		for(JRadioButton r : race) {
			raceGroup.add(r);  //group the different races
			r.setBackground(Color.LIGHT_GRAY); //give each JRadioButton a white background
			racePanel.add(r); //add each race JRadioButton to the panel 
		}
		
		racePanel.setBackground(Color.LIGHT_GRAY);
		racePanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.GRAY), "Select a Race"));
		add(racePanel);
	}
	
	public void reset() {
		playerNameText.setText(null);
		charNameText.setText("");
		charAgeText.setText("");
	}
}
